package com.guozhi.demo.dev;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 默认从配置文件中读取类名
 */
public class GetClassName {

    public GetClassName(String propertiesPath) throws IOException {
        reloadClassName(propertiesPath);
    }

    // 配置文件的实体类
    private String propertiesPath;
    private Properties properties;

    // 配置文件中属性的前缀
    public static final String PREFIX_CLASS_NAME = "gzDev.ClassName.";


    public String getClassName(String alias) {
        return String.valueOf(properties.getProperty(PREFIX_CLASS_NAME + alias));
    }

    // 重新加载配置文件中的类
    public void reloadClassName() throws IOException {
        reloadClassName(this.propertiesPath);
    }

    public void reloadClassName(String propertiesPath) throws IOException {
        this.propertiesPath = propertiesPath;
        properties = new Properties();
        InputStream inputStream = Object.class.getResourceAsStream(propertiesPath);
        properties.load(inputStream);
        inputStream.close();
    }


}
